# Replication Code of "Exponential Random Graph Models for Dynamic Signed Networks: An Application to International Politics"

------------



Description: 

This is the accompanying code repository for the paper Fritz et al. (2024) - ''Exponential Random Graph Models for Dynamic Signed Networks: An Application to International Politics''.
The code folder contains the R code to replicate all computations of the paper together with an R package implementing the SERGM.
The replication package includes all data needed to reproduce the results of the paper. 
The sources of the data are described in Section 3.1 of the Supplemental Materials. The script includes the preprocessing starting with the raw data. 
For both applications covered in the publication, the scripts rely on two packages to gather the data, namely, 'peacesciencer' and 'signnet'. To guarantee full reproducability in the face of package changes, the current state () of the preprocessed data are saved in ".RDS" files. 

Preparations: 

At first, the following packages need to be installed: 
"RcppArmadillo", "ergm", "stringr", "lpSolveAPI","signnet", "Rcpp",
"ggraph", "igraph", "tidygraph", "ggpubr", "coda", "data.table",
"ggmcmc","gridExtra","grid","Hmisc". To install them, execute the following command:
install.packages("signnet") 

Scripts:

There are three separate folders for the two applications ('International Cooperation and Conflict' from Section 4 in the main mauscript and 'Enmity and Friendship among New Guinean Highland Tribes' from Section 4 in the Supplemental Material)
and the simulation study (detailed in Section 2 in the Supplemental Material and 
split into two scripts according to the Setting 1 and 2).
Accordingly, there are separate files to run the respective analyes. 
The "other_functions.R" script includes routines to ease plotting the results and other miscellaneous functions. 
Following, the runner scripts of each folder are named with the needed computational resources and approximated time for execution: 

1. "install_packages.R": Script to install needed R packages
    - Needed resources: Computer with around 2 GB of RAM.
    - Estimated time: 30 minutes 
2. "application_dca.R": Script for the application in the main paper 
    - Needed resources: Computer with around 10 GB of RAM that allows to parallelize with 10 cores.
    - Estimated time: 3 hours 
3. "application_tribes.R": Script for the application in the main paper 
    - Needed resources: Computer with around 10 GB of RAM that allows to parallelize with 20 cores.
    - Estimated time: 10-30 minutes
4. Simulation Studies: 
    - "simulation_mle" (Setting 1 in Section 2 of the Supplemental Material)
        - Needed resources: Computer with around 100 GB of RAM that allows to parallelize with 10 cores. 
        - Estimated time: 2 days 
    - "simulation_cp" (Setting 2 in Section 2 of the Supplemental Material) 
        - Needed resources: Computer with around 50 GB of RAM that allows to parallelize with 50 cores.
        - Estimated time: 1 hour

Since the full replication takes around 3 days, all results are saved as ".RDS" files. 

Executed on a server with the following info: 


```
sessionInfo()
R version 4.4.1 (2024-06-14)
Platform: x86_64-redhat-linux-gnu
Running under: Red Hat Enterprise Linux 8.10 (Ootpa)

Matrix products: default
BLAS/LAPACK: /usr/lib64/libopenblaso-r0.3.15.so;  LAPACK version 3.9.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: America/New_York
tzcode source: system (glibc)

attached base packages:
[1] parallel  stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] Hmisc_5.1-3       gridExtra_2.3     cowplot_1.1.3     ggmcmc_1.5.1.1    tidyr_1.3.1       dplyr_1.1.4      
 [7] data.table_1.15.4 stringr_1.5.1     ergm.sign_1.0     coda_0.19-4.1     ggpubr_0.6.0      tidygraph_1.3.1  
[13] igraph_2.0.3      ggraph_2.2.1      ggplot2_3.5.1     ergm_4.6.0        network_1.18.2    Rcpp_1.0.12      
[19] signnet_1.0.4    

loaded via a namespace (and not attached):
 [1] tidyselect_1.2.1         viridisLite_0.4.2        farver_2.1.2             viridis_0.6.5           
 [5] fastmap_1.2.0            GGally_2.2.1             tweenr_2.0.3             digest_0.6.35           
 [9] rpart_4.1.23             lifecycle_1.0.4          rle_0.9.2                cluster_2.1.6           
[13] magrittr_2.0.3           compiler_4.4.1           rlang_1.1.3              tools_4.4.1             
[17] utf8_1.2.4               knitr_1.47               ggsignif_0.6.4           htmlwidgets_1.6.4       
[21] labeling_0.4.3           graphlayouts_1.1.1       plyr_1.8.9               RColorBrewer_1.1-3      
[25] abind_1.4-5              withr_3.0.0              foreign_0.8-86           purrr_1.0.2             
[29] nnet_7.3-19              grid_4.4.1               polyclip_1.10-6          fansi_1.0.6             
[33] colorspace_2.1-0         scales_1.3.0             MASS_7.3-60.2            cli_3.6.2               
[37] rmarkdown_2.27           generics_0.1.3           rstudioapi_0.16.0        robustbase_0.99-2       
[41] RcppArmadillo_0.12.8.4.0 cachem_1.1.0             ggforce_0.4.2            base64enc_0.1-3         
[45] vctrs_0.6.5              Matrix_1.7-0             carData_3.0-5            car_3.1-2               
[49] rstatix_0.7.2            ggrepel_0.9.5            Formula_1.2-5            htmlTable_2.4.2         
[53] trust_0.1-8              glue_1.7.0               statnet.common_4.9.0     DEoptimR_1.1-3          
[57] ggstats_0.6.0            stringi_1.8.4            gtable_0.3.5             munsell_0.5.1           
[61] tibble_3.2.1             pillar_1.9.0             htmltools_0.5.8.1        R6_2.5.1                
[65] Rdpack_2.6               evaluate_0.23            lpSolveAPI_5.5.2.0-17.11 lattice_0.22-6          
[69] rbibutils_2.2.16         backports_1.5.0          memoise_2.0.1            broom_1.0.6             
[73] checkmate_2.3.1          xfun_0.44                pkgconfig_2.0.3 
```